---
sidebar_position: 1
tags: [boilerplate, tdd, bdd]
---

# 🧪 test

> `test(message: string, cb: () => void)` | `test(cb: () => void)`

`test` is a helper to assist you in such cases:

- Use the [`beforeEach` and `afterEach`](/docs/2.x.x/documentation/helpers/before-after-each/in-code) for each `test` performed
- Isolate or group your tests in the same file
- Run tests in the same file in parallel

## Basic Usage

### Isolating scopes

```ts
import { test, assert } from 'poku';

test(() => {
  const myVar = 'a';

  assert.strictEqual(myVar, 'a', 'My first test helper');
});

test(() => {
  const myVar = 'b';

  assert.strictEqual(myVar, 'b', 'My second test helper');
});
```

### Grouping tests

```ts
import { test, assert } from 'poku';

test(() => {
  assert.equal(1 + 1, 2, '1 + 1 should be 2');
  assert.equal(2 + 2, 4, '2 + 2 should be 4');
});
```

```ts
import { test, assert } from 'poku';

test('Sum tests', () => {
  assert.equal(1 + 1, 2);
  assert.equal(2 + 2, 4);
});
```

```ts
import { test, assert } from 'poku';

test('Sum tests', () => {
  assert.equal(1 + 1, 2, '1 + 1 should be 2');
  assert.equal(2 + 2, 4, '2 + 2 should be 4');
});
```

### Waiting for promises

```ts
import { test } from 'poku';

await test(async () => {
  // do anything you want
});

await test(async () => {
  // do anything you want
});
```

### Running in parallel

```ts
import { test } from 'poku';

test(async () => {
  // do anything you want
});

test(async () => {
  // do anything you want
});
```

### Waiting for multiple promises

```ts
import { test } from 'poku';

// do something before

await Promise.all([
  test(async () => {
    // do anything you want
  }),

  test(async () => {
    // do anything you want
  }),
]);

// do something after
```

:::tip
You can think on it as `beforeAll` and `afterAll`.
:::
